package com.changli03.threadsafe.nosafe;

public class WindowTest {
    public static void main(String[] args) {
        Window w1 = new Window();
        Window w2 = new Window();
        Window w3 = new Window();
        w1.setName("窗口1");
        w2.setName("窗口2");
        w3.setName("窗口3");
        w1.start();
        w2.start();
        w3.start();
    }
}
class Window extends Thread {
    static int ticketnum = 100;

    @Override
    public void run() {
        while (true) {
//            synchronized (this) {
//            }
            if (ticketnum > 0) {
                System.out.println(Thread.currentThread().getName() + "票号为:" + ticketnum);
                ticketnum--;
            }
            else{
                break;
            }
        }
    }
}
